package fr.emn.integration.synthese.controle;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.SQLException;

import javax.swing.JOptionPane;

import fr.emn.integration.synthese.abstraction.Cours;
import fr.emn.integration.synthese.abstraction.Module;
import fr.emn.integration.synthese.presentation.ModuleDialog;

public class ControlJButtonSaveModule implements ActionListener {

	private Cours modele;
	private boolean creation;
	private ModuleDialog parent;

	public ControlJButtonSaveModule(ModuleDialog parent, Cours modele,
			boolean creation) {
		this.modele = modele;
		this.creation = creation;
		this.parent = parent;
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		Module m = new Module(parent.getNom(), parent.getResponsable());
		try {
			modele.saveModule(m, creation);
			parent.setVisible(false);
		} catch (SQLException e1) {
			JOptionPane.showMessageDialog(parent, "On ne peut pas!", "Erreur!",
					JOptionPane.ERROR_MESSAGE);
		}
	}

}
